using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Apache.Cassandra;


namespace Cassandraemon
{


	public static class CounterColumnExtensions
	{
		public static CounterColumn SetName(this CounterColumn source, object name)
		{
			source.Name = name.ToCassandraByte();
			return source;
		}
		
		public static CounterColumn SetValue(this CounterColumn source, long value)
		{
			source.Value = value;
			return source;
		}
		
		public static CounterColumn SetNameValue(this CounterColumn source, object name, long value)
		{
			source.Name = name.ToCassandraByte();
			source.Value = value;
			return source;
		}
		
		
		public static List<CounterColumn> Add(this ICollection<CounterColumn> source, object name, long value)
		{
			source.Add(new CounterColumn().SetNameValue(name, value));
			return source.ToList();
		}

		#region Comparisons

		static readonly IEqualityComparer<CounterColumn> _CounterColumnComparerByName =
			new SelectComparer<CounterColumn, byte[]>(
				counterColumn => counterColumn.Name,
				SequenceComparer<byte>.Default);

		public static IEqualityComparer<CounterColumn> CounterColumnComparerByName
		{
			get { return CounterColumnExtensions._CounterColumnComparerByName; }
		}

		#endregion
	}
}
